package com.yangjun.common.timetask;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.codehaus.jackson.JsonGenerationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yangjun.dao.mybatis.mapper.stockAnalysis.BatchDetMapper;
import com.yangjun.entity.stockAnalysis.BatchDetEntity;
import com.yangjun.utils.JSONUtils;
import com.yangjun.utils.RedisClientLocalUtils;

@Component
public class ScheduledStockAnalysisCacheTasks {

	@Autowired
	private BatchDetMapper saDaoMy;
	private static RedisClientLocalUtils rc = new RedisClientLocalUtils();
	@Scheduled(cron = "0 */5 * * * *")
	public void batchdetCache() {
		
		System.err.println("ScheduledStockAnalysisCacheTasks 调度开启");
		Map<String, String> parms = new HashMap<String, String>();
		parms.put("batchtype", "1");
		String key = "BatchDet_batchtype_default_1";
		PageHelper.startPage(1,10, true, true, true);
		PageInfo<BatchDetEntity> resultMap = new PageInfo<BatchDetEntity>(saDaoMy.select(parms));
		try {
			rc.setKeyValue(key, JSONUtils.objToStr(resultMap));
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
